<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>todoList</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <input type="text" v-model="search" placeholder="请搜索内容">
        <!-- <button @click="SearchArrs">点击搜索</button> -->
        <br>
        <input type="text" placeholder="请输入内容" @keyup.enter="add" v-model="inpAddVal">
        <button @click="add" :value="inpAddVal">点击添加</button>
        <ul>
            <li v-for="item of SearchArrs" :key="item.id">
                <input type="checkbox">
                {{item.ball}}
                <button>点击删除</button>
            </li>
        </ul>
        <span>全选</span>
        <input type="checkbox">
    </div>
    <script>
        Vue.config.productionTip = false;

        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    search: "",
                    inpAddVal: "",
                    Arrs: [
                        {
                            id: 1,
                            ball: "足球"
                        },
                        {
                            id: 2,
                            ball: "蓝球"
                        }
                    ]
                }
            },
            methods: {
                add(e) {
                    // console.log(this.inpAddVal);
                    // console.log((this.Arrs.find(item=>item.ball === this.inpAddVal)));
                    if (this.Arrs.find(item => item.ball === this.inpAddVal)) {
                        this.inpAddVal = null
                        alert("请不要添加重复的内容")
                        return
                    }
                    if (this.inpAddVal === "") {
                        alert("请输入内容")
                        return
                    } else {
                        this.Arrs.unshift(
                            {
                                id: Math.random().toString(36).substr(2),
                                ball: e.target.value
                            }
                        )
                        this.inpAddVal = null
                    }

                }
            },
            computed: {
                SearchArrs() {
                    return this.Arrs.filter(item => {
                        return item.ball.includes(this.search)
                    })
                }
            }
        })
    </script>
</body>

</html>